require("./utils/config");

var e = require("./utils/request"), t = require("./utils/api"), o = require("./utils/storage");

App({
    globalData: {
        hasLogin: !1,
        themeColor: "#007D64",
        systemHeight: 0,
        systemWidth: 0
    },
    onLaunch: function(a) {
        var n = this, s = wx.getUpdateManager();
        wx.getUpdateManager().onUpdateReady(function() {
            wx.showModal({
                title: "更新提示",
                content: "新版本已经准备好，是否重启应用？",
                success: function(e) {
                    e.confirm && s.applyUpdate();
                }
            });
        }), wx.getSystemInfo({
            success: function(e) {
                n.globalData.systemHeight = e.windowHeight, n.globalData.systemWidth = e.windowWidth;
            }
        });
        var i = wx.getStorageSync("logs") || [];
        i.unshift(Date.now()), wx.setStorageSync("logs", i), wx.login({
            success: function(a) {
                console.log("code1", a.code), e.request(e.HttpMethod.POST, t.apiRoute.getWeChatOpenId, {
                    code: a.code
                }).then(function(a) {
                    //lhd
                    a = {
                        "code":"20000",
                        "data":1
                    }
                    if ("20000" == a.code) {
                        console.log("登录获取OpenId：", a.data), o.setStorage(o.storageKey.openId, a.data);
                        var n = o.getStorageSync(o.storageKey.phoneNumber), s = o.getStorageSync(o.storageKey.isRelateOpenId);
                        null != a.data && null != a.data && "" != a.data && null != n && null != n && "" != n && (null != s && null != s && "1" == s || e.request(e.HttpMethod.POST, t.apiRoute.loginByOpenIdOrUserId, {
                            openId: a.data,
                            mobile: n
                        }).then(function(e) {
                            "20000" == e.code && (console.log("关联OpenId成功"), o.setStorage(o.storageKey.isRelateOpenId, "1"));
                        }));
                    }
                });
            }
        });
    },
    onShow: function(e) {
        "pages/temporary/temporary" == e.path && 1038 == e.scene && wx.navigateBack({
            delta: 1
        });
    }
});